package com.sun.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

@Component
@Slf4j
public class MyServletRequestListener implements ServletRequestListener {
    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
        log.info("request end");
        HttpServletRequest servletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest();
        log.info("request域中保存的那么为:{}",servletRequest.getRequestURL());
    }

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
        HttpServletRequest servletRequest = (HttpServletRequest) servletRequestEvent.getServletRequest();
        log.info("session id为:{}",servletRequest.getRequestedSessionId());
        log.info("request url为：{}",servletRequest.getRequestURL());
        servletRequest.setAttribute("name","孙学腾");
    }
}
